package org.demo.rabbitmq;

import com.rabbitmq.client.AMQP.Queue.DeclareOk;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Send {
	public static void main(String[] args) throws Exception {
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost("localhost");
		Connection conn = factory.newConnection();
		Channel channel = conn.createChannel();
		String queueName = "hello2";
		//Add a new queue  如果有不需要创建
		DeclareOk declareOk=channel.queueDeclare(queueName, false, false, false, null);
		System.out.println("当前消息数量消息"+declareOk.getMessageCount());
		String message = "Hello world 3!";
		channel.basicPublish("", queueName, null, message.getBytes());
		channel.close();
		conn.close();
	}

}
